package com.moyun.zbmy.zizhou.ui.adapter.holder;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.moyun.zbmy.zizhou.R;
import com.moyun.zbmy.zizhou.base.BaseActivity;
import com.moyun.zbmy.zizhou.beans.NewAdvertisementBean;
import com.moyun.zbmy.zizhou.beans.NewSpecialAreaBean;
import com.moyun.zbmy.zizhou.ui.activities.AdvertPicInfoActivity;
import com.moyun.zbmy.zizhou.ui.activities.H5NormalActivity;
import com.moyun.zbmy.zizhou.ui.activities.LivingActivity;
import com.moyun.zbmy.zizhou.ui.utils.GlideUtil;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 广告
 */
public class NewAdvertisementHolder extends BaseAbsHolder<NewAdvertisementBean>   {

    public boolean isMute = true;
    @BindView(R.id.item_advert_title)
    protected CustomFontTextView advertTitle;
    @BindView(R.id.item_advert_img)
    protected ImageView advertImg;
    @BindView(R.id.item_advert_big_img)
    protected ImageView advertBigImg;
    @BindView(R.id.item_advert_tip)
    protected CustomFontTextView itemAdvertTip;
    private NewAdvertisementBean advertisementBean;

    public NewAdvertisementHolder(Context context, View itemView ) {
        super(context, itemView);

    }

    public boolean isMute() {
        return isMute;
    }

    public void setMute(boolean mute) {
        isMute = mute;
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(NewAdvertisementBean a) {
        advertisementBean = a;
        if(a.isBig()){
            advertBigImg.setVisibility(View.VISIBLE);
            advertImg.setVisibility(View.GONE);
            GlideUtil.getGlideWithSmall169DefCenterCrop(context, advertisementBean.getImage219()).into(advertBigImg);
        }else{
            advertBigImg.setVisibility(View.GONE);
            advertImg.setVisibility(View.VISIBLE);
            GlideUtil.getGlideWithSmall169DefCenterCrop(context, advertisementBean.getImage()).into(advertImg);
        }
        if("0".equalsIgnoreCase(advertisementBean.getIfDisplayAdvertisingWords())){
            itemAdvertTip.setVisibility(View.VISIBLE);
        }else{
            itemAdvertTip.setVisibility(View.GONE);
        }
        advertTitle.setText(advertisementBean.getName());
    }


    @OnClick({R.id.advert_layout })
    public void itemClick(View view) {
        if(null!=advertisementBean.getAdvertType()) {
            if (advertisementBean.getAdvertType().equalsIgnoreCase("0") && !TextUtils.isEmpty(advertisementBean.getContentImage())) {
                //跳转图片预览
                Intent intent = new Intent(context, AdvertPicInfoActivity.class);
                List<String> pics = new ArrayList<>();
                pics.add(advertisementBean.getContentImage());
                intent.putExtra(AdvertPicInfoActivity.PIC_LIST, (Serializable) pics);
                List<NewAdvertisementBean> picInfo = new ArrayList<>();
                NewAdvertisementBean infoBean = new NewAdvertisementBean();
                infoBean.setId(advertisementBean.getId());
                infoBean.setContentImage(advertisementBean.getContentImage());
                infoBean.setH5(advertisementBean.getH5());
                infoBean.setName(advertisementBean.getName());
                picInfo.add(infoBean);
                intent.putExtra(AdvertPicInfoActivity.PIC_INFO_LIST, (Serializable) picInfo);
                context.startActivity(intent);

            } else if (advertisementBean.getAdvertType().equalsIgnoreCase("2") && !TextUtils.isEmpty(advertisementBean.getH5())) {
                //跳转h5外链
                Intent intent = new Intent(context, H5NormalActivity.class);
                intent.putExtra(H5NormalActivity.EX_HTML, advertisementBean.getH5());
                intent.putExtra(H5NormalActivity.H5_NEWS_ID, advertisementBean.getId());
                intent.putExtra(H5NormalActivity.IS_ADVERT_H5, true);
                intent.putExtra(H5NormalActivity.IS_NEED_SHARE, true);
                intent.putExtra(H5NormalActivity.IS_NEED_TOKEN, false);
                context.startActivity(intent);

            }
        }

    }

}
